package com.copote;


import com.copote.key.Key;
import com.copote.util.AesUtil;
import com.copote.util.RsaUtils;

/**
 * @Author liubo
 * @Date 2021-06-04 9:31
 */
public class Main {
    public static void main(String[] args) {
        try {
            if(args[0].equals("1")){
                //前端加密后端解密
                System.err.println(Main.one(args[1]));
            }else if(args[0].equals("2")){
                //后端加密前端解密
                System.err.println(Main.two(args[1]));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static String one(String decrypt) throws Exception {
        //String decrypt ="XAnZ82MQn6VOTiY1JR8jPhfFwxfO3buzAlALh0TiNOtVtQpvfnETrTcPmBNCNGmPvEcEy/toG/SoDf7TJQ+i/ldpUQ+W128s7Gy4CEFEspmxGW28UrY93EIh2wlVpY+5O7Q+nE9Z/gw8RJb2SAU2sWxExDm96aKrgcfHHcaG4ig=|$|&|$|kMcspIvsjUbGbzbg1yCNFO95m9sBEkoNPUFc0AMeDBy1ELOhZqhCo/klPNKa0ZfoZQUsEVqIEqVp3tuY0VymKTrJoGSVvuYIyqZadtlRBHOp6J72xGz0b95AaJTka/uQ";
        String[] split = decrypt.split(Key.STRING_SEPARATOR_REGULAR);
        String aesKey = RsaUtils.decryptByPrivateKey(split[0], Key.key_2_private);
        AesUtil.setsKey(aesKey);
        return AesUtil.decrypt(split[1]);
    }


    public static String two(String decrypt) throws Exception {
        //String decrypt ="Gy+iDKEnoTRld2/Mn74RqX/JJdMfuuKv1cu7uaF8PEIu36vHDT+S7oWPw1OTwP+U7FBE97Aw82VK2Xn2aYTSmOxj6kDFiSdyIkr+HKg6Npb13FEONpBYxl5f1PpZZgNg414W7Owjde9TwIYmnTNcWU8pRo/cGizRKiYV3ZeQAlU=|$|&|$|n21EQf3ygNC0IZ+5EMwJd5pRtHnWtFZuTrbT0R1FoIPeWuMyM0ZBWFO/oWcz+IIjAqKgMh5cUthGazgnqio59zG6OQNdWmT4OmwxENjZlaxktaOCmOiLMkkbw1FqRxmTuTI5NGZ8EJYy/2sUvU1MuoRPz3WmMxaw1Vvc0ySpSw7j3+g23vaQuJ523m1zm21e";
        String[] split = decrypt.split(Key.STRING_SEPARATOR_REGULAR);
        String aesKey = RsaUtils.decryptByPrivateKey(split[0], Key.key_1_private);
        AesUtil.setsKey(aesKey);
        return AesUtil.decrypt(split[1]);
    }

}
